package ace.cmp.json.jackson.config;

import ace.cmp.json.api.JsonService;
import ace.cmp.json.api.JsonUtils;
import ace.cmp.json.jackson.JacksonService;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * @author Caspar 自动配置默认 {@link JsonService} 使用jackson
 */
@ConditionalOnProperty(value = "ace.cmp.json.jackson.enable", matchIfMissing = true)
@ConditionalOnClass(value = {JsonService.class})
@ConditionalOnMissingBean(value = {JsonService.class})
@AutoConfiguration
public class JacksonAutoConfigure {

  @Bean
  @ConditionalOnMissingBean
  public JsonService jsonPlugin() {
    JacksonService jacksonPlugin = new JacksonService();
    JsonUtils.setJsonService(jacksonPlugin);
    return jacksonPlugin;
  }
}
